// CSE571 - io-manager.cpp          
// Authors: Jonathan Wald, Guangle Fan
// Defines the active object used in the synchronous layer of the app.

#ifndef IO_Manager_H
#define IO_Manager_H

#include "ace/Svc_Handler.h"
#include <set>
#include "async-io-svc-handler.h"

class ACE_Message_Block;

typedef std::set<ACE_Message_Block*> WriteMap;

class IOManager : public ACE_Task<ACE_MT_SYNCH>
{
 public:
  static IOManager* instance();
  typedef ACE_Task<ACE_MT_SYNCH> inherited;
  IOManager (void);
  int open (int pool_size = 1);
  virtual int close (u_long flags = 0);
  int enqueue (AsyncIOSvcHandler *handler, bool write);
  int enqueue_resume(AsyncIOSvcHandler *handler);
  int enqueue_suspend(AsyncIOSvcHandler *handler);
  bool write_block (AsyncIOSvcHandler *handler, ACE_Message_Block* mb);
  typedef ACE_Atomic_Op<ACE_Mutex, int> counter_t;
  WriteMap write_map;
  bool shut_down;
  bool read_data;

 protected:
  int svc (void);

 private:
  static IOManager* instance_;


};

#endif
